<template>
  <NewCard title="收银台" isright="isright" isleft="isleft">
    <template slot="left">
      <svg-icon icon-class="return_icon" class="returnIcon" @click="returnBtn"/>
    </template>
    <template slot="right">
      <span class="hintRight"
        >请在 {{ minute }}:{{ second }}内完成支付，超时订单自动关闭</span
      >
    </template>
    <div class="pay">
      <div class="pay_main">
        <div class="infomoneny">
          <h3>{{ firstName }}-{{ secondaryName }}-{{ threeName }}</h3>
          <p>发送格式:PDF</p>
          <p>应付问金:{{ paymoneny }}</p>
        </div>
        <el-row>
          <el-col :span="12" :md="24">
            <p class="inputTitle">接收信息</p>
            <el-input v-model="useremail" placeholder="请输入邮箱">
              <!-- <button slot="suffix" class="acceptEmail">换绑邮箱</button> -->
            </el-input>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <Compay
              ref="compay"
              :orderinfo="orderinfo"
              :acceptEmail="useremail"
            ></Compay>
          </el-col>
        </el-row>
      </div>
      <div class="payBtn" v-show="btnpay">
        <p>
          应付问金：<span>{{ paymoneny }}</span>
        </p>
        <el-button round @click="askGoldPay">立即支付</el-button>
      </div>
    </div>
  </NewCard>
</template>

<script>
import NewCard from "@/wss/components/newCard.vue";
import Compay from "@/BMViews/components/Compay/index.vue";
import {
  getpriceCommissionListApi,
  getCircleAmountListApi,
  addConsultTypeListApi,
} from "@/BMViews/api/work/consult.js";
import { getDepositVoucherPayApi } from "@/BMViews/api/financial/deposit.js";

export default {
  name: "Pay",
  props: {
    formdata: { type: Object },
    getConsumptionapilistfn: {
      type: Function,
      default: () => {},
    },
  },
  components: { NewCard, Compay },
  data() {
    return {
      // 消费订单参数对象
      orderinfo: { id: "", amount: "" },
      pageing: { pageNum: 1, pageSize: 100 },
      minutes: 15, //分
      seconds: 0, //，秒
      firstName: "",
      secondaryName: "",
      threeName: "",
      balance: true, //充值按钮的显示隐藏
      isright: true, //显示时间提示支付
      acceptEmail: "", //接收邮箱
      activeName: "askGold", //默认显示问金支付
      btnpay: true, //支付按钮的显示
      useremail: this.$store.state.user.email,
      circleUrl:
        "https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png", //头像
      askRadio: "0", //1为选中，0为不选择

      //订单支付金额
      paymoneny: "",
      //当前支付的方式
      currentPayWay: "",
    };
  },
  mounted() {
    const _this = this;
    _this.$bus.$on("topay", (e) => {
      _this.paymoneny = e.price;
      _this.firstName = e.firstName;
      _this.secondaryName = e.secondaryName;
      _this.threeName = e.threeName;
      _this.orderinfo.amount = e.price;
    });
    _this.$bus.$on("EventGetOrder", (id) => {
      _this.orderinfo.id = id;
    });
    _this.$bus.$on("hidePayBtn", this.handleClick);
  },
  created() {
    // this.getpriceCommissionListApifn();
    if (this.$store.getters.userId) {
      this.getCircleAmountListApifn();
    }
    this.countdown();
  },
  //监听时间
  watch: {
    second: {
      handler(newVal) {
        this.num(newVal);
      },
    },
    minute: {
      handler(newVal) {
        this.num(newVal);
      },
    },
  },
  //计算时间
  computed: {
    second() {
      return this.num(this.seconds);
    },
    minute() {
      return this.num(this.minutes);
    },
  },
  methods: {
    // 点击返回按钮
    returnBtn(){
      this.$bus.$emit('returnBtnShow',2)
    },

    num(n) {
      return n < 10 ? "0" + n : "" + n;
    },
    //倒计时
    countdown() {
      var _this = this;
      var time = window.setInterval(function () {
        if (_this.seconds === 0 && _this.minutes !== 0) {
          _this.seconds = 59;
          _this.minutes -= 1;
        } else if (_this.minutes === 0 && _this.seconds === 0) {
          _this.seconds = 0;
          window.clearInterval(time);
          changes();
        } else {
          _this.seconds -= 1;
        }
      }, 1000);
    },
    changes() {
      this.$router.push({ path: "/Bm-Consult/finance" });
    },

    //查询支付账户
    async getCircleAmountListApifn() {
      const { pageNum, pageSize } = this.pageing;
      let result = await getCircleAmountListApi({ pageNum, pageSize });
      if (result.code == 200) {
        this.mountlist = result.rows;
      }
    },

    // 问金支付
    async askGoldPay() {
      console.log(this.$refs.compay, "this.$refs.compay");
      let circleId = this.$refs.compay.getCirecleDefaultPay();
      let { code, msg } = await getDepositVoucherPayApi({
        circleId,
        orderId: this.orderinfo.id,
        email: this.useremail,
      });
      if (code != 200) return;
      this.$message({
        message: msg,
        type: "success",
      });
      // this.$router.push("/Bm-personalCenter/homepage");
      // 路由传参orderId
      this.$router.push({
        path: "/Bm-personalCenter/messageCenter",
        query: { orderId: this.orderinfo.orderNo },
      });
      this.getConsumptionapilistfn();
    },
    handleClick(tab) {
      if (tab == "scanQr") {
        this.btnpay = false;
      } else {
        this.btnpay = true;
      }
    },
  },
};
</script>

<style scoped>
ul {
  list-style: none;
  margin: 0;
  padding: 0;
}
.hintRight {
  font-size: 12px;
  color: #999;
}
::v-deep .el-card__body {
  position: relative;
}
/* 支付信息 */
.pay_main {
  margin-bottom: 70px;
}
.pay_main .el-card {
  border-radius: 12px;
}
::v-deep .pay_main .el-card__body {
  padding: 20px;
}
.pay_main h3 {
  margin: 0;
  margin-bottom: 12px;
  font-size: 16px;
  color: #333;
}
.pay_main p {
  font-size: 14px;
  color: #999;
  margin: 0;
  line-height: 24px;
}
.pay_main .el-row {
  margin-top: 40px;
}
.pay .infomoneny {
  padding: 10px;
  border: 1px solid #ecedf0;
  border-radius: 5px;
}
::v-deep .pay_main .el-row .el-input__inner {
  border-radius: 8px;
  height: 44px;
  line-height: 44px;
}

/* 选择专家 */
.selectExpert h3 {
  font-size: 18px;
  color: #333;
  margin-top: 20px;
}
.selectBox > .selectTitle {
  font-size: 12px;
  color: #666;
  margin-top: 15px;
  margin-bottom: 5px;
}
.selectBox ul {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
}
.selectBox li {
  width: 32%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border: 1px solid #efefef;
  border-radius: 12px;
  padding: 15px;
  transition: all 0.3s;
  cursor: pointer;
}
.selectBox li > .expertInfo {
  display: flex;
  align-items: center;
}
.selectBox li > .expertInfo > p {
  font-size: 16px;
  color: #333;
  margin-left: 10px;
}
.selectBox li > .expertInfo > img {
  width: 40px;
  height: 40px;
  border-radius: 50%;
}
.selectBox li > p {
  font-size: 16px;
  color: #39486f;
}
.selectBox li:hover,
.selectBox li.isChecked {
  background-color: #39486f;
}
.selectBox li:hover p,
.selectBox li.isChecked p {
  color: #fff;
}

/* 选择专家 end*/

.pay_main .el-row .acceptEmail {
  border: 0;
  padding: 5px 0;
  margin: 7px 0;
  margin-right: 10px;
  font-size: 14px;
  color: #bababa;
  background: #fff;
  cursor: pointer;
}
.pay_main .el-row .acceptEmail:hover {
  color: #f87a23;
}
.pay_main .inputTitle {
  font-size: 18px;
  color: #333;
  margin-bottom: 15px;
}
.pay_main .inputTitle span {
  font-size: 14px;
  color: #999;
}
::v-deep .pay_main .el-tabs__header {
  border: 0;
  margin-bottom: 24px;
}
::v-deep .pay_main .el-tabs__nav {
  width: 100%;
  display: flex;
  justify-content: space-between;
  border: 0;
}
::v-deep .pay_main .el-tabs__item {
  width: 49%;
  border-radius: 8px;
  text-align: center;
  font-size: 14px;
  border: 0;
  background-color: #fafafa;
}
::v-deep .pay_main .el-tabs__item.is-active {
  background-color: #f1f3ff;
  color: #39486f;
}
::v-deep .pay_main .el-tabs__item:hover {
  color: #39486f;
}

.askGold {
  list-style: none;
  padding: 0;
  margin: 0;
  width: 100%;
}
.askGold li {
  display: flex;
  margin-bottom: 24px;
}
.askGold li .el-avatar {
  margin-right: 14px;
}
.askGold .askInfo h3 {
  margin-bottom: 5px;
  font-size: 16px;
  color: #333;
}
.askGold .askInfo {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid #ecedf0;
  padding-bottom: 24px;
}
.askGold .askInfo p {
  font-size: 12px;
  color: #666;
}
.askGold .askInfo button {
  color: #39486f;
  border-color: #39486f;
  padding: 5px 15px;
}
::v-deep .askInfo .el-radio__label {
  display: none;
}
::v-deep .askInfo .el-radio .el-radio__inner {
  width: 24px;
  height: 24px;
  border-color: #bbbbbb;
  background: #fff;
}
::v-deep .askInfo .el-radio .is-disabled .el-radio__inner {
  background: #f2f2f2;
}
::v-deep .askInfo .el-radio .is-checked .el-radio__inner {
  border-color: #f87a23;
  background: #f87a23;
}
::v-deep .askInfo .el-radio__input.is-checked .el-radio__inner::after {
  content: "";
  width: 11px;
  height: 7px;
  border: 3px solid white;
  border-top: transparent;
  border-right: transparent;
  text-align: center;
  display: block;
  position: absolute;
  top: 6px;
  left: 5px;
  vertical-align: middle;
  transform: rotate(-45deg);
  border-radius: 0px;
  background: none;
}
.payBtn {
  position: absolute;
  bottom: 0;
  left: 0;
  z-index: 9;
  width: 100%;
  background-color: #fff;
  border-top: 1px solid #ecedf0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 30px;
}
.payBtn p {
  margin: 0;
  font-size: 14px;
}
.payBtn p > span {
  color: #f87a23;
  font-size: 16px;
}
.payBtn .el-button {
  background-color: #f87a23;
  border-color: #f87a23;
  color: #fff;
  font-size: 14px;
  padding: 10px 50px;
}
.payBtn .el-button:hover {
  opacity: 0.9;
}

.scanQr {
  text-align: center;
}
.scanQr img {
  width: 150px;
}
.scanQr p {
  color: #f87a23;
  font-size: 18px;
}
.scanQr span {
  font-size: 12px;
  color: #999;
}
</style>
<style>
.el-tooltip__popper.is-light {
  border: 0 !important;
  box-shadow: 2px 4px 16px 2px #e2e2e2;
  padding: 20px;
}
.el-tooltip__popper.is-light h3,
.el-tooltip__popper.is-light p {
  margin: 0;
}
.el-tooltip__popper.is-light h3 {
  font-size: 14px;
  color: #666;
  margin-bottom: 8px;
}
.el-tooltip__popper.is-light p {
  color: #666;
  font-size: 12px;
  line-height: 22px;
}
.el-tooltip__popper .popper__arrow {
  /* 上方箭头 */
  border-top-color: #fff !important;
  /* 下方箭头 */
  border-bottom-color: #fff !important;
}
.el-tooltip__popper .popper__arrow:after {
  border-top-color: #fff !important;
  border-bottom-color: #fff !important;
}

@media (max-width: 1120px) {
  ::v-deep .top .right {
    flex: 2;
  }
  ::v-deep .pay_main .el-card__body {
    padding: 12px 20px !important;
  }

  .pay_main .el-row {
    margin-top: 30px;
  }
  .pay_main .el-row .el-row {
    margin-top: 0px;
  }
}
</style>